package com.li.jiang.controller;


import cn.hutool.core.bean.BeanUtil;
import com.li.jiang.obj.pojo.Company;
import com.li.jiang.obj.pojo.CompanyVO;
import com.li.jiang.service.impl.CompanyServiceImpl;
import com.li.jiang.utils.ReturnMessage;
import com.li.jiang.utils.role.RequireRoles;
import com.li.jiang.utils.role.Role;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 企业信息表 前端控制器
 * </p>
 *
 * @author 李江
 * @since 2024-04-12
 */
@RestController
@ApiModel("公司管理")
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    private CompanyServiceImpl companyService;
    @GetMapping("/getInfoByUid/{uid}")
    public CompanyVO getCompanyByUid(@PathVariable("uid") Long uid){
        return companyService.getCompanyByUid(uid);
    }
    @RequireRoles(role = {Role.COMPANY,Role.ADMIN})
    @PostMapping("/updateInfoById")
    public ReturnMessage UpdateCompanyById( @RequestBody Company  company){
        System.out.println("接受公司信息成功："+ company);
        Company c = companyService.UpdateCompanyByCid(company);
        System.out.println("更新公司信息成功："+ c);
        return ReturnMessage.success("更新成功",c);
    }
    @GetMapping("/getInfoByName/{name}")
    public CompanyVO getCompanyByName(@PathVariable("name") String name){
        Company company = companyService.getCompanyByName(name);
        return BeanUtil.copyProperties(company,CompanyVO.class);
    }
}
